﻿using MaterialDesignThemes.Wpf;
using MVVM.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Themes.Controls
{
    /// <summary>
    /// MessageDialog.xaml 的交互逻辑
    /// </summary>
    public partial class MessageDialog : UserControl
    {
        public MessageDialog()
        {
            InitializeComponent();
        }
    }

    /// <summary>
    /// 消息对话框ViewModel
    /// </summary>
    public class MessageDialogViewModel : DialogViewModel
    {
        /// <summary>
        /// 
        /// </summary>
        public MessageDialogViewModel()
        {
            this.Title = "提示信息";
            this.CancelButtonVisibility = Visibility.Collapsed;//默认不显示取消按钮
            this.OkButtonContent = "确定";
            this.CancelButtonContent = "取消";
        }

        /// <summary>
        /// 取消按钮显示设置
        /// </summary>
        public Visibility CancelButtonVisibility
        {
            get
            {
                return this.GetValue<Visibility>();
            }
            set
            {
                this.SetValue(value);
            }
        }

        /// <summary>
        /// Ok按钮显示的文字
        /// </summary>
        public String OkButtonContent
        {
            get
            {
                return this.GetValue<String>();
            }
            set
            {
                this.SetValue(value);
            }
        }

        /// <summary>
        /// Cancel按钮显示的文字
        /// </summary>
        public String CancelButtonContent
        {
            get
            {
                return this.GetValue<String>();
            }
            set
            {
                this.SetValue(value);
            }
        }

        /// <summary>
        /// 显示图标
        /// </summary>
        public PackIconKind Kind
        {
            get
            {
                return this.GetValue<PackIconKind>();
            }
            set
            {
                this.SetValue(value);
            }
        }

        /// <summary>
        /// 确定事件
        /// </summary>
        public Func<Boolean> OkAction { get; set; }

        /// <summary>
        /// 取消事件
        /// </summary>
        public Func<Boolean> CancelAction { get; set; }

        /// <summary>
        /// 确定
        /// </summary>
        public DelegateCommand OkCommand => new(() =>
        {
            if (OkAction?.Invoke() == true)
            {
                this.Hide();
            }
        });

        /// <summary>
        /// 取消
        /// </summary>
        public DelegateCommand CancelCommand => new(() =>
        {
            if (CancelAction?.Invoke() == true)
            {
                this.Hide();
            }
        });

        /// <summary>
        /// 显示提示对话框
        /// </summary>
        /// <param name="content"></param>
        /// <param name="title"></param>
        /// <param name="pack">
        /// MessageOutline 用于普通的图示信息
        /// MessageAlertOutline 用于危险操作提示信息
        /// MessageCheckOutline 用于完成的提示信息
        /// </param>
        public void ShowMessage(String content, String title = "提示信息", PackIconKind pack = PackIconKind.MessageAlertOutline)
        {
            CancelButtonVisibility = Visibility.Collapsed;
            this.Content = content;
            this.Title = title;
            base.Show();
        }

        /// <summary>
        /// 显示询问对话框
        /// </summary>
        /// <param name="content"></param>
        /// <param name="title"></param>
        public void ShowQuestion(String content, String title = "提示信息")
        {
            this.Kind = PackIconKind.MessageQuestionOutline;//用于询问的提示信息
            CancelButtonVisibility = Visibility.Visible;
            this.Content = content;
            this.Title = title;
            base.Show();
        }
    }
}
